//
// TcpServerConnection.h
//
// $Id: //poco/1.4/Net/include/Poco/Net/TcpServerConnection.h#1 $
//
// Library: Net
// Package: TcpServer
// Module:  TcpServerConnection
//
// Definition of the TcpServerConnection class.
//
// Copyright (c) 2005-2006, Applied Informatics Software Engineering GmbH.
// and Contributors.
//
// SPDX-License-Identifier:	BSL-1.0
//


#ifndef Net_TcpServerConnection_INCLUDED
#define Net_TcpServerConnection_INCLUDED


#include "Poco/Net/Net.h"
#include "Poco/Runnable.h"


namespace Poco {
namespace Net {


class Net_API TcpServerConnection: public Poco::Runnable
	/// The abstract base class for Tcp server connections
	/// created by TcpServer.
	///
	/// Derived classes must override the run() method
	/// (inherited from Runnable). Furthermore, a
	/// TcpServerConnectionFactory must be provided for the subclass.
	///
	/// The run() method must perform the complete handling
	/// of the client connection. As soon as the run() method
	/// returns, the server connection object is destroyed and
	/// the connection is automatically closed.
	///
	/// A new TcpServerConnection object will be created for
	/// each new client connection that is accepted by
	/// TcpServer.
{
public:
	TcpServerConnection(int fd);
		/// Creates the TcpServerConnection using the given
		/// stream socket.

	virtual ~TcpServerConnection();
		/// Destroys the TcpServerConnection.

protected:
	int fd();
		/// Returns a reference to the underlying socket.

	void start();
		/// Calls run() and catches any exceptions that
		/// might be thrown by run().

private:
	TcpServerConnection();
	TcpServerConnection(const TcpServerConnection&);
	TcpServerConnection& operator = (const TcpServerConnection&);
	
	int 			m_fd;
	
	friend class TcpServerDispatcher;
};


//
// inlines
//
inline int TcpServerConnection::fd()
{
	return m_fd;
}


} } // namespace Poco::Net


#endif // Net_TcpServerConnection_INCLUDED
